package com.example.photoview.util;

/**
 * Android Log封装
 */


import android.util.Log;

public class LogUtil {
    public static final int LOG_OFF = -1;
    public static final int LOG_INFO = 1;
    public static final int LOG_DEBUG = 2;
    public static final int LOG_ERROR = 3;
    public static final int LOG_ALL = 4;
    private static String tag = "ooo--->";
    private static int logLevel = 10;

    public LogUtil() {
    }

    public static void d(String msg) {
        String appendedMsg = appendMsgAndInfo(msg, getCurrentInfo());
        if (logLevel >= 2) {
            Log.d(tag, appendedMsg);
        }

    }

    public static void e(String msg, Throwable tr) {
        String appendedMsg = appendMsgAndInfo(msg, getCurrentInfo());
        if (logLevel >= 3) {
            Log.e(tag, appendedMsg, tr);
        }

    }

    public static void i(String msg) {
        String appendedMsg = appendMsgAndInfo(msg, getCurrentInfo());
        if (logLevel >= 1) {
            Log.i(tag, appendedMsg);
        }

    }

    private static String getCurrentInfo() {
        StackTraceElement[] eles = Thread.currentThread().getStackTrace();
        StackTraceElement targetEle = eles[5];
        String info = "(" + targetEle.getClassName() + "." + targetEle.getMethodName() + ":" + targetEle.getLineNumber() + ")";
        return info;
    }

    private static String appendMsgAndInfo(String msg, String info) {
        return msg + " " + getCurrentInfo();
    }

    public static String getTag() {
        return tag;
    }

    public static void setTag(String tag) {
        tag = tag;
    }

    public static int getLogLevel() {
        return logLevel;
    }

    public static void setLogLevel(int logLevel) {
        logLevel = logLevel;
    }
}
